﻿@model IPagedList<BlogListViewModel>

@using X.PagedList
@using X.PagedList.Mvc.Core

@{
    ViewBag.Title = "文章管理";

    string se = ViewBag.Search == null ? " " : (string)ViewBag.Search;
    int pg = ViewBag.Page == null ? 1 : (int)ViewBag.Page;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>

    <div class="row">
    <div class="col-md-10 col-md-offset-1">
        <div class="panel panel-headline">
            <div class="panel-heading">
                <h3 class="panel-title">文章管理</h3>
            </div>
            <div class="panel-body">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-lg-11">
                            <div class="container-fluid">
                                <div class="row">
                                    <div class="col-lg-5">
                                        <form>
                                            <div class="input-group">
                                                <input type="search" class="form-control" name="search" value="@ViewBag.Search" />
                                                <span class="input-group-btn">
                                                    <button class="btn btn-primary">搜索</button>
                                                </span>
                                            </div>
                                        </form>
                                    </div>
                                    <div class="col-lg-4">
                                        
                                        @*<div class="col-lg-2" style="width:150px;">
                                            <a href="~/ForumManage/Blog/Add" class="btn btn-success">
                                                <i class="fa fa-plus-circle"></i> 新增权限
                                            </a>
                                        </div>*@
                                        @*col-lg-7 col-lg-offset-1*@
                                        <div class="input-group" style="margin-left: 0px; width: 194px;">
                                            <form asp-action="Index" asp-controller="Blog">
                                                <select class="form-control state" style="width: 120px">
                                                    <option value="0">审核失败</option>
                                                    <option value="1">审核中</option>
                                                    <option value="2">审核成功</option>
                                                </select>
                                                <span class="input-group-btn">
                                                    <a class="btn btn-primary action-state">查询</a>
                                                </span>
                                            </form>
                                        </div>

                                    </div>

                                </div>
                            </div>


                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-12">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>
                                            <input type="checkbox" name="checkAll" id="checkAll" />
                                            全选
                                        </th>
                                        <th>序号</th>
                                        <th>文章标题</th>
                                        <th>文章内容</th>
                                        <th>文章状态</th>
                                        <th>发布用户</th>
                                        <th>文章类型</th>
                                        <th>发布形式</th>
                                        <th>文章等级</th>
                                        <th>点赞数</th>
                                        <th>厌恶值</th>
                                        <th>修改时间</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @for(var i = 0 ; i < Model.Count; i++)
                                    {
                                        <tr>
                                            <td>
                                                <input type="checkbox" name="checkMe" id="checkMe" />
                                                @Html.Hidden("Id",Model[i].Id)
                                            </td>

                                            <td>
                                                @(i+1)
                                            </td>

                                            <td>
                                                @Model[i].Title
                                            </td>

                                            <td>
                                                @Model[i].Content
                                            </td>

                                            <td>
                                                @Model[i].StateCode
                                            </td>

                                            <td>
                                                @Model[i].UsersTitle
                                            </td>

                                            <td>
                                                @Model[i].ArticleCateTitle
                                            </td>

                                            <td>
                                                @Model[i].ReleaseFormTitle
                                            </td>

                                            <td>
                                                @Model[i].LevelTitle
                                            </td>

                                            <td>
                                                @Model[i].Like
                                            </td>

                                            <td>
                                                @Model[i].Trample
                                            </td>

                                             <td>
                                                @Model[i].UpdateTime
                                            </td>

                                             <td>
                                                 @*<form action="../../ForumManage/Blog/Delete" id="form_@Model[i].Id" method="post">
                                                     <a href="../../ForumManage/Blog/UpdateStateCode" method="post" class="btn btn-warning">
                                                        <i class="fa fa-pencil"></i> 审核成功
                                                     </a>
                                                      @Html.Hidden("Id",Model[i].Id)
                                                      <button type="button" onclick="deleteData('form_@Model[i].Id')" class="btn btn-danger">
                                                          <i class="fa fa-trash"></i> 删除
                                                      </button>
                                                 </form>*@

                                                 <button type="button" onclick="updateState(@Model[i].Id,'@Model[i].StateCode')" class="btn btn-danger">
                                                      <i class="fa fa-trash"></i> 审核成功
                                                 </button>

                                                 <button type="button" onclick="deleteState(@Model[i].Id,'@Model[i].StateCode')" class="btn btn-danger">
                                                      <i class="fa fa-trash"></i> 拒绝审核
                                                 </button>

                                            </td>
                                        </tr>

                                    }
                                </tbody>
                            </table>

                            <nav aria-label="Page navigation">
                                <div class="pagination">
                                  <!-- 分页的地方我们现在用的内容是一段Html Helper分页标签  -->
                                  @Html.PagedListPager(Model,page => Url.Action("Index","Blog",new{page,search=ViewBag.Search},"https","localhost:7087"))
                                </div>
                            </nav>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@section Scripts
{
    <script>
     function deleteData(formId)
     {
        if(confirm("确认删除么?"))
        {
            //确认了删除
            var form = "#"+formId;

            $(form).submit();
        }
     }

     function updateState(page,stateCode)
     {

         console.log(page);
         console.log(stateCode);

         if(stateCode == "待审核")
         {
            window.location.href="../../../../ForumManage/Blog/UpdateStateCode/"+ page +"/"+ 2 +"";
         }
         else if(stateCode == "审核失败")
         {
            window.location.href="../../../../ForumManage/Blog/UpdateStateCode/"+ page +"/"+ 1 +"";
         }

        //var stid = "#" + stateId;
        //console.log(stid);
        //$(stid).submit();
     }

     function deleteState(page,stateCode)
     {
         if(stateCode == "待审核")
         {
            window.location.href="../../../../ForumManage/Blog/UpdateStateCode/"+ page +"/"+ 0 +"";
         }
         else if(stateCode == "审核成功")
         {
            window.location.href="../../../../ForumManage/Blog/UpdateStateCode/"+ page +"/"+ 1 +"";
         }
     }
    
     $(".action-state").click(function()
     {

         var value = $(".state").val();
         //debugger
         //console.log(@se);
         //console.log(@pg);
         //console.log(value);
         //debugger
         window.location.href="../../../../ForumManage/Blog/Index/"+@pg+"/"+value+"";
     });

     


    </script>
}

</body>
</html>
